/* $RCSFile: ADNDynActivityBase.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/CRMWrapper3/DynEntities/ADNDynActivityBase.cs $
 * $log$
 * Revision 19 2010/10/02 14:01:48  christian.surieux
 *   Corrected a bug in allmost everyADNDyn file for PrimaryFieldVualue
 * Revision 6 2010/08/06 19:56:32  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;
using CrmSdk;

namespace AddonNice.CRMWrapper
{
    /// <summary>
    /// Base class for two branch: activitypointer and activity
    /// </summary>
	public class ADNDynActivityBase : DynEntity
	{
        /// <summary>
		/// Reserved for template methods: do not use directly
		/// </summary>
        public ADNDynActivityBase(): base()
		{}

        public ADNDynActivityBase(CRMWrapperBase w,string subj,string schemaNm)
			: base(w, schemaNm)
		{
            subject     =   subj;
		}

        public ADNDynActivityBase(CRMWrapperBase w,string schemaNm, Guid CrmId)
			: base(w,schemaNm, CrmId)
		{}

		public ADNDynActivityBase(CRMWrapperBase w, InternalDynamicEntity e)
			: base(w, e,null,null)
		{}

		public ADNDynActivityBase(CRMWrapperBase w, InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
			: base(w, e,prop,s)
		{}

		public ADNDynActivityBase(CRMWrapperBase w,string entName, InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
			: base(w,entName,e,prop,s)
		{}

        public ADNDynActivityBase(ResetWrapperHandler fn,string subj,string schemaNm)
			: base(fn, schemaNm)
		{
            subject     =   subj;
		}

        public ADNDynActivityBase(ResetWrapperHandler fn,string schemaNm, Guid CrmId)
			: base(fn,schemaNm, CrmId)
		{}

		public ADNDynActivityBase(ResetWrapperHandler fn, InternalDynamicEntity e)
			: base(fn, e,null,null)
		{}

		public ADNDynActivityBase(ResetWrapperHandler fn, InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
			: base(fn, e,prop,s)
		{}

		public ADNDynActivityBase(ResetWrapperHandler fn,string entName, InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
			: base(fn,entName,e,prop,s)
		{}


        [CrmDynAttribute(CrmStr.email), CrmDynAttribute(CrmStr.appointment), CrmDynAttribute(CrmStr.phonecall),CrmDynAttribute(CrmStr.task),CrmDynAttribute(CrmStr.fax),CrmDynAttribute(CrmStr.letter)]
		public Guid activityid
		{
			get
			{
				return KeyPropertyValue(CrmStr.activityid);
			}
			set
			{
				AddKeyProperty(CrmStr.activityid, value);
			}
		}

        protected override void SetCrmIdProperty(Guid crmId)
        {
           if ( !dicProperty.ContainsKey(CrmStr.activityid) || KeyPropertyValue(CrmStr.activityid) != crmId )
                activityid  =   crmId;
        }

        public override Guid PrimaryKeyGuidValue
        {
           get
           {
                return activityid;
           }
           set
           {
               activityid    =   value;
           }
        }

        public override string PrimaryFieldName
        {
            get
            {
               return CrmStr.subject;
            }
           set
           {}
       }

        public override string PrimaryFieldStringValue
        {
            get
            {
                return subject;
            }
            set
            {
                subject =   value;
            }
        }

        /// <summary>
        /// Gets or sets the subject associated with the activity. 
        /// </summary>
        [CrmDynAttribute(CrmStr.email), CrmDynAttribute(CrmStr.appointment), CrmDynAttribute(CrmStr.phonecall),CrmDynAttribute(CrmStr.task),CrmDynAttribute(CrmStr.fax),CrmDynAttribute(CrmStr.letter)]
        public string subject
        {
            get
            {
                return StringPropertyValue(CrmStr.subject);
            }
            set
            {
                AddStringProperty(CrmStr.subject,value);
            }
        }

        protected string _DefaultRegardingObjectName   =   CrmStr.account;
		public virtual string DefaultRegardingObjectName // TBD redefine for each specific activity
		{
			get
			{
				return _DefaultRegardingObjectName;
			}
			set
			{
                switch (value)
                {
                    case CrmStr.account:
                    case CrmStr.contact:
                    case CrmStr.bulkoperation: // ie quick campaign, ok for mail
                    case CrmStr.campaign:  //beware, not valid for emails, only campaignactivity allowed
                    case CrmStr.campaignactivity:
                    case CrmStr.incident:
                    case CrmStr.contract:
                    case CrmStr.invoice:
                    case CrmStr.lead:
                    case CrmStr.opportunity:
                    case CrmStr.salesorder:
                    case CrmStr.quote:
                        _DefaultRegardingObjectName  =   value;
                        break;
                }
			}
		}

        /// <summary>
        /// Gets or sets the ID of the entity instance with which the activity is associated. 
        /// </summary>
        [CrmDynAttribute(CrmStr.email), CrmDynAttribute(CrmStr.appointment), CrmDynAttribute(CrmStr.phonecall),CrmDynAttribute(CrmStr.task),CrmDynAttribute(CrmStr.fax),CrmDynAttribute(CrmStr.letter)]
        public Guid regardingobjectid
        {
            get
            {
                return LookupPropertyValue(CrmStr.regardingobjectid);
            }
            set
            {
                AddLookupProperty(CrmStr.regardingobjectid,DefaultRegardingObjectName,value);
            }
        }

        public string regardingobjectType
        {
            get
            {
                return LookupPropertyType(CrmStr.regardingobjectid);
            }
        }

        public string regardingobjectName
        {
            get
            {
                return LookupPropertyName(CrmStr.regardingobjectid);
            }
        }
        
        /// <summary>
        /// Gets or sets the scheduled duration of the activity, specified in minutes. 
        /// </summary>
        [CrmDynAttribute(CrmStr.email), CrmDynAttribute(CrmStr.appointment), CrmDynAttribute(CrmStr.phonecall),CrmDynAttribute(CrmStr.task),CrmDynAttribute(CrmStr.fax),CrmDynAttribute(CrmStr.letter)]
        public int scheduleddurationminutes
        {
            get
            {
                return NumberPropertyValue(CrmStr.scheduleddurationminutes);
            }
            set
            {
                AddNumberProperty(CrmStr.scheduleddurationminutes,value);
            }
        }

        /// <summary>
        /// Gets or sets the scheduled end time of the activity. 
        /// </summary>
        [CrmDynAttribute(CrmStr.email), CrmDynAttribute(CrmStr.appointment), CrmDynAttribute(CrmStr.phonecall),CrmDynAttribute(CrmStr.task),CrmDynAttribute(CrmStr.fax),CrmDynAttribute(CrmStr.letter)]
        public string scheduledend
        {
            get
            {
                return DateTimePropertyValue(CrmStr.scheduledend);
            }
            set
            {
                AddDateTimeProperty(CrmStr.scheduledend,value);
            }
        }

        /// <summary>
        /// Gets or sets the scheduled start time of the activity. 
        /// </summary>
        [CrmDynAttribute(CrmStr.email), CrmDynAttribute(CrmStr.appointment), CrmDynAttribute(CrmStr.phonecall),CrmDynAttribute(CrmStr.task),CrmDynAttribute(CrmStr.fax),CrmDynAttribute(CrmStr.letter)]
        public string scheduledstart
        {
            get
            {
                return DateTimePropertyValue(CrmStr.scheduledstart);
            }
            set
            {
                AddDateTimeProperty(CrmStr.scheduledstart,value);
            }
        }

        /// <summary>
        /// Gets or sets the duration for the activity specified in minutes. 
        /// </summary>
        [CrmDynAttribute(CrmStr.email), CrmDynAttribute(CrmStr.appointment), CrmDynAttribute(CrmStr.phonecall),CrmDynAttribute(CrmStr.task),CrmDynAttribute(CrmStr.fax),CrmDynAttribute(CrmStr.letter)]
        public int actualdurationminutes
        {
            get
            {
                return NumberPropertyValue(CrmStr.actualdurationminutes);
            }
            set
            {
                AddNumberProperty(CrmStr.actualdurationminutes,value);
            }
        }

        /// <summary>
        /// Gets or sets the time when the activity ends. 
        /// </summary>
        [CrmDynAttribute(CrmStr.email), CrmDynAttribute(CrmStr.appointment), CrmDynAttribute(CrmStr.phonecall),CrmDynAttribute(CrmStr.task),CrmDynAttribute(CrmStr.fax),CrmDynAttribute(CrmStr.letter)]
        public string actualend
        {
            get
            {
                return DateTimePropertyValue(CrmStr.actualend);
            }
            set
            {
                AddDateTimeProperty(CrmStr.actualend,value);
            }
        }

        /// <summary>
        /// Gets or sets the time when the activity begins. 
        /// </summary>
        [CrmDynAttribute(CrmStr.email), CrmDynAttribute(CrmStr.appointment), CrmDynAttribute(CrmStr.phonecall),CrmDynAttribute(CrmStr.task),CrmDynAttribute(CrmStr.fax),CrmDynAttribute(CrmStr.letter)]
        public string actualstart
        {
            get
            {
                return DateTimePropertyValue(CrmStr.actualstart);
            }
            set
            {
                AddDateTimeProperty(CrmStr.actualstart,value);
            }
        }

        /// <summary>
        /// Gets or sets the main body text of the activity. 
        /// </summary>
        [CrmDynAttribute(CrmStr.email), CrmDynAttribute(CrmStr.appointment), CrmDynAttribute(CrmStr.phonecall),CrmDynAttribute(CrmStr.task),CrmDynAttribute(CrmStr.fax),CrmDynAttribute(CrmStr.letter)]
        public string description
        {
            get
            {
                return StringPropertyValue(CrmStr.description);
            }
            set
            {
                AddStringProperty(CrmStr.description,value);
            }
        }
 
        /// <summary>
        /// Gets or sets the priority code of the activity. 
        /// High 2 Specifies high priority. 
        /// Low 0 Specifies low priority. 
        /// Medium 1 Specifies medium priority. 
        /// </summary>
        [CrmDynAttribute(CrmStr.email), CrmDynAttribute(CrmStr.appointment), CrmDynAttribute(CrmStr.phonecall),CrmDynAttribute(CrmStr.task),CrmDynAttribute(CrmStr.fax),CrmDynAttribute(CrmStr.letter)]
        public int prioritycode
        {
            get
            {
                return PicklistPropertyIntValue(CrmStr.prioritycode);
            }
            set
            {
                AddPicklistProperty(CrmStr.prioritycode,value);
            }
        }

        public string prioritycodeLabel
        {
            get
            {
                return PicklistPropertyLabelValue(CrmStr.prioritycode);
            }
        }

        /// <summary>
        /// Gets or sets a value that indicates whether the activity is billed as part of resolving a case. 
        /// </summary>
        [CrmDynAttribute(CrmStr.email), CrmDynAttribute(CrmStr.appointment), CrmDynAttribute(CrmStr.phonecall),CrmDynAttribute(CrmStr.task),CrmDynAttribute(CrmStr.fax),CrmDynAttribute(CrmStr.letter)]
        public bool isbilled
        {
            get
            {
                return BooleanPropertyValue(CrmStr.isbilled);
            }
            set
            {
                AddBooleanProperty(CrmStr.isbilled,value);
            }
        }

        /// <summary>
        /// Gets or sets a value that indicates whether the activity was created by a workflow rule. 
        /// </summary>
        [CrmDynAttribute(CrmStr.email), CrmDynAttribute(CrmStr.appointment), CrmDynAttribute(CrmStr.phonecall),CrmDynAttribute(CrmStr.task),CrmDynAttribute(CrmStr.fax),CrmDynAttribute(CrmStr.letter)]
        public bool isworkflowcreated
        {
            get
            {
                return BooleanPropertyValue(CrmStr.isworkflowcreated);
            }
            set
            {
                AddBooleanProperty(CrmStr.isworkflowcreated,value);
            }
        }

        /// <summary>
        /// Gets or sets the ID for the associated service. 
        /// </summary>
        [CrmDynAttribute(CrmStr.email), CrmDynAttribute(CrmStr.appointment), CrmDynAttribute(CrmStr.phonecall),CrmDynAttribute(CrmStr.task),CrmDynAttribute(CrmStr.fax),CrmDynAttribute(CrmStr.letter)]
        public Guid serviceid
        {
            get
            {
                return LookupPropertyValue(CrmStr.serviceid);
            }
            set
            {
                AddLookupProperty(CrmStr.serviceid,CrmStr.service,value);
            }
        }
    }
}
